<?php
include ("functions.php");

header('Content-Type: text/javascript');
header('Cache-Control: no-cache');
header('Pragma: no-cache');


$name = $_POST["name"].trim();
$lastName = $_POST["lastName"].trim();
$comment = $_POST["comment"].trim();
$gender = $_POST["gender"].trim();
$country = $_POST["country"].trim();
$date = date("Y-m-d");
$email = $_POST["email"].trim();

if ($name != '' && $lastName != '' && $comment != '' && $gender != '' && $country != ''){
	if (!$link = connect()) {
		die ("Error en la conexión con la base de datos");
	}
	//Insert data into database
	$sql = "INSERT INTO gb_entries VALUES ('', '$name', '$lastName', '$gender', '$country', '$comment', '$date', '$email');";

	if (!mysql_db_query("guestbook", $sql, $link)) {
  		die ("<br/>Hubo un error al insertar datos en la base de datos");
	}
	
	disconnect($link);	
}

?>